package com.banciyuan.bcywebview.biz.ask.answer;

import android.content.Context;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.banciyuan.bcywebview.R;
import com.banciyuan.bcywebview.base.helper.data.UserDataHelper;
import com.banciyuan.bcywebview.base.myinterface.PushActionInterface;
import com.banciyuan.bcywebview.utils.http.CommonApiUtils;
import com.banciyuan.bcywebview.utils.http.StatusCodeUtils;
import com.banciyuan.bcywebview.utils.http.VolleyQueue;

public class WriteAnswerHelper {

	private Context mContext;
	private PushActionInterface mInterface;
	private RequestQueue mQueue;

	private Boolean ifAnswering = false;

	private String ua_id = "";
	private String mContent = "";

	public WriteAnswerHelper(Context mContext, PushActionInterface mInterface, String ua_id) {
		this.mContext = mContext;
		this.mInterface = mInterface;
		this.ua_id = ua_id;
		mQueue = VolleyQueue.getRquest(this.mContext);
	}

	public void doPush() {
		if (ifAnswering) return;
		else ifAnswering = true;

		Response.Listener<String> onSuccess = new Response.Listener<String>() {
			@Override
			public void onResponse(String response) {
				if(StatusCodeUtils.dealStatusCode(response, mContext, mInterface)) {
					mInterface.PushSuccess("");
					ifAnswering = false;
				}
			} 
		};

		Response.ErrorListener onError = new Response.ErrorListener() {
			@Override
			public void onErrorResponse(VolleyError error) {
				ifAnswering = false;
				mInterface.onNetError(mContext.getString(R.string.net_check_first));
			}
		};
		CommonApiUtils.doAnswer(mContext, mQueue, onSuccess, onError, ua_id, 
				UserDataHelper.getInstance(mContext).getToken(), mContent);
	}

	public void setContent(String mContent) {
		this.mContent = mContent;
	}
}